package com.xps.purifierapp;

import android.app.Application;
import android.content.Context;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Vibrator;
import android.support.annotation.RequiresApi;

import com.jude.utils.JUtils;
import com.squareup.leakcanary.LeakCanary;
import com.xps.purifierapp.utils.AppCommond;
import com.xps.purifierapp.utils.SharedPreferencesUtils;
import com.xps.purifierapp.view.activity.MainActivity;

import org.greenrobot.eventbus.EventBus;

import cn.jpush.android.api.JPushInterface;

@RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
public class App extends Application {
    private static App INSTANCE;
    Vibrator vibrator;
    @Override
    public void onCreate() {
        super.onCreate();
        SharedPreferencesUtils.init(this);
        INSTANCE = this;
//        检测内存泄露
//        if (LeakCanary.isInAnalyzerProcess(this)) {
//            return;
//        }
//        LeakCanary.install(this);
//        Jutlis工具类初始话
        JUtils.initialize(this);

        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
    }

    public static App getInstance() {
        return INSTANCE;
    }

    public void JPuchNotice() {
        AppCommond appCommond = new AppCommond.Builder()
                .setOpration(AppCommond.CLOSE_ACTIVITY)
                .setRequestcloseAcname(MainActivity.class.getSimpleName())
                .build();
        EventBus.getDefault().post(appCommond);
        vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        long[] pattern = {100, 400, 100, 400};   // 停止 开启 停止 开启
        vibrator.vibrate(pattern, -1);
        startAlarm();
    }
    public void startAlarm() {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (notification == null) return;
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    }
}
